<template>
	<view class="">
		<view class="container-conversation">
			<!-- 顶部适配 -->
			<!-- <u-navbar height="0">
				<view class="u-nav-slot" slot="left"></view>
			</u-navbar> -->
			<!-- 标题栏 -->
			<view class="topIcon">
				{{$t('change.消息')}}
				<view class="msgRt">
				</view>
			</view>
			<!-- <u-search placeholder="搜索" v-model="searchKey" :show-action="false"></u-search> -->
			<!-- <view class="imgBar">
				<view>
					<image src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/images/imgBar/haoyou.png"></image>
					<text>粉丝</text>
				</view>
				<view>
					<image src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/images/imgBar/zan.png"></image>
					<text>赞</text>
				</view>
				<view>
					<image src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/images/imgBar/shafa.png"></image>
					<text>动态</text>
				</view>
				<view>
					<image src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/images/imgBar/chakan.png"></image>
					<text>系统通知</text>
				</view>
			</view> -->
		</view>
		<!-- 消息 -->
		<view class="">
			<view>
				<message></message>
			</view>
		</view>
		<tabbar />
	</view>
</template>

<script>
	import message from '@/components/im/message';
	import { storeToRefs } from 'pinia';
	import { useMsgStore } from '@/store/message';
	import { useloginStore } from '@/store/login';
	import pinia from '@/store/index'
	// import scan from '@/common/scan.js'
	const msgStore = useMsgStore(pinia)
	const loginStore = useloginStore(pinia)
	const { unread , sysUnread } = storeToRefs(msgStore);
	export default {
		components: {
			message
		},
		data() {
			return {
				show: false,
				searchKey:'毁灭吧',
				globalConfig: loginStore.globalConfig,
				PageCur: 'message',
				PageName: '消息',
				TabCur:0,
				modelName:false
			};
		},
		onShow() {
			
		},
		mounted(){
			// 检查本地联系人,如果没有才去请求接口
			let contacts=uni.getStorageSync('allContacts');
			if(!contacts.length){
				this.initContacts();
			}
			// 监听ws状态,如果重新连接了,要更新联系人
			uni.$on('socketStatus',(e)=>{
				if(e){
					this.initContacts();
				}
			})
		},
		methods: {
			closeModel(){
				this.modelName=false;
			},
			// scan(){
			// 	scan.scanQr();
			// },
			NavChange: function(item) {
				this.PageCur = item.name
				this.PageName = item.title
			},
			showContacts(){
				this.TabCur==1 ? this.TabCur=0 :this.TabCur=1
			},
			initContacts(){
				console.log('initContacts -- ')
				this.modelName='';
				this.$api.msgApi.initContacts().then(res => {
					if(res.code == 0){
						// 设置消息未读数和系统消息未读数
						msgStore.sysUnread=res.count;
						msgStore.initContacts(res.data);
					}
				})
			},
			addGroup(){
				uni.navigateTo({
					url: '/pages/index/userSelection?type=1'
				})
			},
			addFriend(){
				uni.navigateTo({
					url: '/pages/contacts/search'
				})
			},
			search(){
				const type = this.PageCur=="message" ? 1 : 2;
				uni.navigateTo({
					url: '/pages/index/search?type='+type
				})
			}
		},
	};
</script>


<style>
	page{
		background: #fff;
	}
</style>

<style scoped lang="scss">
	.container-conversation {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		width: 100%;
		padding: 0 30rpx;
		.boxPopBg {
			position: absolute;
			right: 20rpx;
			top: 10rpx;
			background: #303133;
			width: 230rpx;
			height: auto;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			border-radius: 6rpx;

			>text {
				width: 100%;
				height: 80rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #fff;
				border-bottom: 1rpx solid #fff;
				font-size: 30rpx;
			}

			.topTag {
				position: absolute;
				width: 0;
				height: 0;
				border-bottom: solid 5px #303133;
				border-right: solid 5px transparent;
				border-left: solid 5px transparent;
				right: 15px;
				top: 0px;
				z-index: 999;
			}
		}

		.notice {
			display: flex;
			align-items: center;
			justify-content: space-evenly;
			height: 130rpx;
			background: #ffffff;
			box-shadow: 0px 4rpx 27rpx 11rpx rgba(80, 15, 101, 0.09);
			border-radius: 19rpx;
			margin-bottom: 30rpx;

			>image {
				width: 56rpx;
				height: 56rpx;
			}

			>view {
				display: flex;
				flex-direction: column;
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;

				text {
					font-size: 24rpx;
					font-weight: bold;
					color: #999999;
				}
			}

			>text {
				width: 138rpx;
				height: 57rpx;
				background: linear-gradient(99deg, #fd8be0 0%, #48c5fe 100%);
				border-radius: 29rpx;
				font-size: 30rpx;
				font-weight: bold;
				color: #ffffff;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.imgBar {
			padding: 40rpx 0;
			display: flex;
			justify-content: space-between;

			view {
				display: flex;
				flex-direction: column;
				align-items: center;

				image {
					width: 90rpx;
					height: 90rpx;
				}

				text {
					margin-top: 20rpx;
					font-size: 30rpx;
					color: #333;
				}
			}
		}

		.topIcon {
			display: flex;
			justify-content: space-between;
			font-size: 40rpx;
			height: 80rpx;
			align-items: center;
			margin-bottom: 30rpx;
			font-weight: bold;
			z-index: 99999;
			margin-top: 90rpx;

			/*  #ifdef  MP-WEIXIN */
			.msgRt {
				margin-right: 200rpx;
			}

			/*  #endif  */

			view {
				display: flex;
				align-items: center;

				.u-icon {
					margin-left: 30rpx;
				}
			}
		}
	}

	.scroll-box {}

	.margintop-bar {
		margin-bottom: 160 rpx;
	}

	.btn-show-more {
		display: flex;
		width: 160rpx;
		height: 160rpx;
		padding-left: 3rpx;
	}

	.picker {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 96rpx;
	}
</style>